function ajax(options) {
    var { type = "get", url, data = "", async = "true", dataType = "text", success } = options;
    if (typeof data == "object") {
        var arr = [];
        for (var key in data) {
            var val = data[key];
            arr.push(key + "=" + val);
        }
        data = arr.join("&");
        // console.log(data);
    }
    var xhr = new XMLHttpRequest();
    if (type.toLowerCase() == "post") {
        xhr.open(type, url, async);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(data);
    } else if (type.toLowerCase() == "get") {
        xhr.open(type, data ? url + "?" + data : url, async);
        xhr.send();
    }

    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var result = xhr.responseText;
            if (dataType.toLowerCase() == "json") {
                result = JSON.parse(result);
            }
            if (success) {
                success(result);
            }
        }
    }
}